package cn.liulin.spring_boot_study.config;

import cn.liulin.spring_boot_study.pojo.User;
import org.apache.commons.dbcp2.BasicDataSourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * cn.liulin.spring_boot_study.config$
 *
 * @author ll
 * @date 2021-10-22 11:05:56
 **/
@Configuration
public class AppConfig {

    //只要装载的bean名称不一样即可，类型无所谓一不一样
    @Bean(name = "user")
    public User initUser() {
        User user = new User();
        user.setName("zhangsan ");
        return user;
    }

    @Bean(name = "dataSource")
    public DataSource getDataSource() {
        Properties properties = new Properties();
        properties.setProperty("driver", "com.mysql.jdbc.Driver");
        properties.setProperty("url", "jdbc:mysql://119.23.240.130:3306/wuchekaifa?useSSL=false&characterEncoding=utf8");
        properties.setProperty("username", "root");
        properties.setProperty("password", "Carfi666!");
        DataSource dataSource = null;
        try {
            dataSource = BasicDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataSource;
    }
}
